<?php   // $Id: fact_creer.php 275 2008-08-12 20:41:04Z pcoustillas $ ?>
<?php
/*Copyright (C) 2003-2004 Guy Hendrickx
Licensed under the terms of the GNU  General Public License:http://www.opensource.org/licenses/gpl-license.php
File Authors:Guy Hendrickx 
Modification: Pierre coustillas */
require_once("include/verif.php");
require_once("include/config/common.php");
require_once("include/config/var.php");
require_once("include/language/$lang.php");
require_once("include/utils.php");
require_once("include/headers.php");

?>

<table width="760" border="0" class="page" align="center">
	<tr>
		<td class="page" align="center">
			<?php
			require_once("include/head.php");
			?>
		</td>
	</tr>
	<tr>
		<td class="page" align="center">
			<?php

			if ($user_fact == "n") {
				echo "<h1>$lang_facture_droit</h1>";
				exit;
			}

			if (isset($_GET['message']))
			{
				echo "<h1>" . $_GET['message'] . "</h1>";
			}

			$mois = date("m");
			$annee = date("Y");
			$jour = date("d");

			$sql_fact = "SELECT date_fact FROM ${tblpref}facture ORDER BY date_fact DESC LIMIT 1";
			$result = mysql_query($sql_fact) or die("Erreur SQL !<br/>$sql_fact<br/>" . mysql_error());
			$date_derniere_fact = mysql_result($result,0);
			$date_derniere_fact = sql_to_date($date_derniere_fact); //ne pas déplacer après l'appel à javascript
			?>

			<?php // ne pas déplacer avant le calcul de $date_dernier_fact ?>
			<script language="javascript" src="javascripts/verifier_form.js" type="text/javascript"></script>
			<script type="text/javascript">
			
				function verif_creer_fact()
				{
					if (verifier('formu','black','num_client','egale_a%0','date_deb','vide#date_','date_fin','vide#date_','date_fact','vide#date_#est_inf_a_date%<?php echo $date_derniere_fact ?>','acompte','est_nombre'))
					{
						document.formu.submit();
					} else {
						alert("<?php aff_lang('Une des valeurs saisie n\'est pas correct.\nMerci de corriger avant de poursuivre.') ?>")
					}
			
				}
			</script>
			<center>
			<form name="formu" method="post" action="fact_creer_suite.php">
				<table class="boiteaction">
					<caption><?php echo $lang_facture_creer; ?> &nbsp;  &nbsp;  &nbsp; <?php bouton_aide("fact_creer") ?></caption>
					<tr>
						<td class="texte0" width="50%" id="num_client"> <?php echo $lang_client; ?> </td>
						<td class="texte0" width="50%">
						<?php
							require_once("include/choix_cli.php");
							inclure_combo_client("num_client",0,"formu");
						?>
						</td>
					</tr>
					<tr>
						<td class='<?php echo couleur_alternee (); ?>' id="date_deb"><?php aff_lang("Selectionner les bons à partir du") ?></td>
						<td class='<?php echo couleur_alternee (FALSE); ?>'>
							<input type="text" name="date_deb" value="<?php echo "01/$mois/$annee" ?>" />
							<a href="#" onclick=" window.open('include/pop.calendrier.php?frm=formu&amp;ch=date_deb','calendrier','width=415,height=160,scrollbars=0').focus();"><img src="image/petit_calendrier.gif" border="0" alt="calendrier"/></a>
						</td>
						</tr>
						<tr>
							<td class='<?php echo couleur_alternee (); ?>' id="date_fin"><?php aff_lang("Selectionner les bons jusqu'au") ?></td>
							<td class='<?php echo couleur_alternee (FALSE); ?>'>
							<input type="text" name="date_fin" value="<?php echo "$jour/$mois/$annee" ?>" />
							<a href="#" onclick=" window.open('include/pop.calendrier.php?frm=formu&amp;ch=date_fin','calendrier','width=415,height=160,scrollbars=0').focus();"><img src="image/petit_calendrier.gif" border="0" alt="calendrier"/></a>
							</td>
						</tr>
						<tr>
							<td class='<?php echo couleur_alternee (); ?>' id="date_fact">
								
								<?php echo $lang_facture_date; ?> (<?php echo get_lang("date de la dernière facture") . " : " . $date_derniere_fact . ")" ?>
										
							</td>
							<td class='<?php echo couleur_alternee (FALSE); ?>'>
							<input type="text" name="date_fact" value="<?php echo "$jour/$mois/$annee" ?>" />
							<a href="#" onclick=" window.open('include/pop.calendrier.php?frm=formu&amp;ch=date_fact','calendrier','width=415,height=160,scrollbars=0').focus();"><img src="image/petit_calendrier.gif" alt="calendrier" border="0"/></a>
						</td>
					</tr>

					<tr>
						<td class='<?php echo couleur_alternee (); ?>' id="acompte"><?php echo $lang_acompte; ?></td>
						<td class='<?php echo couleur_alternee (FALSE); ?>'><input type="text" name="acompte"/>&nbsp;<?php echo $devise; ?>&nbsp; &nbsp; &nbsp;</td>
					</tr>

					<tr>
						<td class='<?php echo couleur_alternee (); ?>'>
							<?php echo $lang_ajo_fact ?>
						</td>
						<td class='<?php echo couleur_alternee (FALSE); ?>'>
							<textarea name="coment" cols="45" rows="3"></textarea>
						</td>
					</tr>

					<tr>
						<td class='<?php echo couleur_alternee (); ?>'>
							<?php aff_lang("Ajouter une référence à la facture") ?>
						</td>
						<td class='<?php echo couleur_alternee (FALSE); ?>'>
							<input type="text" name="reference" size="70" maxlength="80" />
						</td>
					</tr>

					<tr>
						<td class="submit" colspan="2">
							<br/>
							<input type="button" onclick="verif_creer_fact()" value="      <?php echo $lang_facture_creer_bouton; ?>      " />
							<br/>&nbsp;
						</td>
					</tr>
				</table>
			</form>
			</center>
			<hr/>

		</td>
	</tr>
	<tr>
		<td>
			<?php
			require_once("include/bas.php");
			?>
		</td>
	</tr>

</table>
</body>
</html>
